package com.yitao.cms.controller.product;

import com.skipper.base.bean.DataOutput;
import com.yitao.cms.mapper.ProductRepository;
import com.yitao.cms.service.product.ProductCmsService;
import com.yitao.cms.utils.BaseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: wwl
 * @Date: 2019/11/28 19:32
 * @Description:
 */
@Api(value = "/productEs", description = "商品ES相关接口", tags = {"cms-productEs"})
@RestController
@RequestMapping(value = "/productEs", produces = {"application/json"})
public class ProductEsTestController {
    @Autowired
    private ProductCmsService productCmsService;
    @Autowired
    private ProductRepository productRepository;
    private BaseUtils baseUtils = BaseUtils.getInstance();

    @ApiOperation("更新ES数据")
    @RequestMapping(value = "/updateEs", method = RequestMethod.POST)
    public DataOutput updateEs(
            @ApiParam(value = "商品id最小值") @RequestParam(value = "idMin")Integer idMin,
            @ApiParam(value = "商品id最大值") @RequestParam(value = "idMnx")Integer idMnx,
            @ApiParam(value = "上下架状态") @RequestParam(value = "sale")Boolean sale
    ) {
        return productCmsService.updateEs(idMin,idMnx,sale);
    }
    @ApiOperation("查询Es数据")
    @RequestMapping(value = "/findProductByES", method = RequestMethod.POST)
    public DataOutput findProductByES(
            @ApiParam(value = "商品id") @RequestParam(value = "id") Long id
    ) {
        return baseUtils.getSuccessMsg(productRepository.getById(id));
    }
}
